<html>
<head>
  <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css">
  <script src="https://apis.google.com/js/api:client.js"></script>
  <script>
    var googleUser = {};
    f = 1;
    var startApp = function() {
      gapi.load('auth2', function() {
        auth2 = gapi.auth2.init({
            client_id: '311192923957-dklnkq4vlc0fcrncbt37v1jkkbb1qvb1.apps.googleusercontent.com', //TODO: 到Google申请的
            cookiepolicy: 'single_host_origin',
        });
    
        auth2.attachClickHandler(document.getElementById('customBtn'), {}, function(){console.log(1);}, function(error) {console.log(error);
        });
      });
    } 

  // var startApp = function() {
  //   gapi.load('auth2', function(){
  //     // Retrieve the singleton for the GoogleAuth library and set up the client.
  //     auth2 = gapi.auth2.init({
  //       client_id: '311192923957-dklnkq4vlc0fcrncbt37v1jkkbb1qvb1.apps.googleusercontent.com',
  //       cookiepolicy: 'single_host_origin',
  //       // Request scopes in addition to 'profile' and 'email'
  //       //scope: 'additional_scope'
  //     });
  //     attachSignin(document.getElementById('customBtn'));
  //   });
  // };

  // function attachSignin(element) {
  //   console.log(element.id);
  //   auth2.attachClickHandler(element, {},
  //       function(googleUser) {
  //         document.getElementById('name').innerText = "Signed in: " +
  //             googleUser.getBasicProfile().getName();
  //       }, function(error) {
  //         alert(JSON.stringify(error, undefined, 2));
  //       });
  // }
  </script>
  <style type="text/css">
    #customBtn {
      display: inline-block;
      background: white;
      color: #444;
      width: 190px;
      border-radius: 5px;
      border: thin solid #888;
      box-shadow: 1px 1px 1px grey;
      white-space: nowrap;
    }
    #customBtn:hover {
      cursor: pointer;
    }
    span.label {
      font-family: serif;
      font-weight: normal;
    }
    span.icon {
      background: url('/identity/sign-in/g-normal.png') transparent 5px 50% no-repeat;
      display: inline-block;
      vertical-align: middle;
      width: 42px;
      height: 42px;
    }
    span.buttonText {
      display: inline-block;
      vertical-align: middle;
      padding-left: 42px;
      padding-right: 42px;
      font-size: 14px;
      font-weight: bold;
      /* Use the Roboto font that is loaded in the <head> */
      font-family: 'Roboto', sans-serif;
    }
  </style>
  </head>
  <body>
  <!-- In the callback, you would hide the gSignInWrapper element on a
  successful sign in -->
  <form id="login_form" action="">
  <!-- <div id="gSignInWrapper"> -->
    <span class="label">Sign in with:</span>
    <button id="customBtn" type="button"><img src="./static/img/icon-google.png" alt="google" style="cursor: pointer;"></button>
    <!-- <div id="customBtn" class="customGPlusSignIn">
      <span class="icon"></span>
      <span class="buttonText">Google</span>
    </div> -->
  <!-- </div> -->
  </form>

  <div id="name"></div>
  <script>startApp();</script>
</body>
</html>